﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SPW.Infrastructure.Models
{

    /// <summary>
    /// 认证结果数据实体
    /// </summary>
    public class AuthorizedResultDataModel
    {
        /// <summary>
        /// 访问token
        /// </summary>
        [JsonProperty("access_token")]
        public string AccessToken { get; set; }
        /// <summary>
        /// 刷新token
        /// </summary>
        [JsonProperty("refresh_token")]
        public string RefreshToken { get; set; }

        #region 登陆者信息
        /// <summary>
        /// 登陆者id
        /// </summary>
        public string Id { get; set; }
        /// <summary>
        /// 昵称
        /// </summary>
        public string NickName { get; set; }
        #endregion

        #region 状态信息
        /// <summary>
        /// 返回代码
        /// </summary>
        [JsonProperty("code")]
        public ResultCodes Code { get; set; } = ResultCodes.Complete;
        /// <summary>
        /// 消息(可选)
        /// </summary>
        [JsonProperty("message")]
        public string Message { get; set; }
        #endregion
    }

    /// <summary>
    /// 结果数据模型
    /// </summary>
    public class ResultDataModel
    {
        /// <summary>
        /// 返回代码
        /// </summary>
        [JsonProperty("code")]
        public ResultCodes Code { get; set; }
        /// <summary>
        /// 成功状态(可选)
        /// </summary>
        [JsonProperty("success")]
        public bool? Success { get; set; }
        /// <summary>
        /// 消息(可选)
        /// </summary>
        [JsonProperty("message")]
        public string Message { get; set; }
        /// <summary>
        /// 数量(可选)
        /// </summary>
        [JsonProperty("count")]
        public int? Count { get; set; }
    }

    public class ResultDataModel<TDataModel> : ResultDataModel where TDataModel : class, new()
    {
        /// <summary>
        /// 数据体(可选)
        /// </summary>
        [JsonProperty("data")]
        public TDataModel Data { get; set; }
    }

    public class ResultDataModel<TDataModel, TOtherModel> : ResultDataModel<TDataModel>
        where TDataModel : class, new()
         where TOtherModel : class, new()
    {
        /// <summary>
        /// 其他数据(可选)
        /// </summary>
        [JsonProperty("other")]
        public TOtherModel Other { get; set; }
    }

    /// <summary>
    /// 返回代码集合
    /// </summary>
    public enum ResultCodes
    {
        /// <summary>
        /// 完成
        /// </summary>
        Complete = 0,
        /// <summary>
        /// 未登录
        /// </summary>
        UnLogin = 401,
        /// <summary>
        /// 未授权
        /// </summary>
        UnAuthorized = 403,
        /// <summary>
        /// 异常
        /// </summary>
        Exception = 500,
    }
}
